import falcon
from wsgiref import simple_server
from keras.models import load_model
from routes import route_doclocalisation
from health import Health


def load_trained_models():
    """
    :return: trained gan for doc localisation
    """
    doc_localisation_model = load_model("saved_models/model.h5")
    return doc_localisation_model


def create_api():
    """
    :return: returns api
    """
    api = falcon.API()

    health_check = Health()
    api.add_route('/health', health_check)

    doc_localisation_model = load_trained_models()

    route = route_doclocalisation(doc_localisation_model)
    api.add_route(route[0], route[1])
    return api


api = application = create_api()
if __name__ == '__main__':
    httpd = simple_server.make_server('0.0.0.0', 8002, api)
    httpd.serve_forever()
